<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<div th:insert="common/common.html"></div>

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function login() {
            $.ajax({
                url: "/user/login", //需要访问的地址
                type: "post", //请求方式, get/post 默认get
                dataType: "json", //返回值数据类型  html/json/xml/text
                data: $("#login_form").serialize(), //前台到后台传入的数据, 没有参数可以不写
                async: true, // 设置ajax自己执行时的同步异步   true异步请求, false代表同步请求  默认是true
                success: function (data) {// 成功回调函数
                    if(data.code){
                        alert("登录成功");
                        toastr.success("登录成功");
                        location.href = "/menu/treeview";
                    }else {
                        toastr.error(data.message);
                    }
                },
                error: function (data) {// 错误回调函数
                    console.log(data);
                    // alert("登录失败");
                    toastr.error("登录失败")
                }
            })
        }
    </script>
</head>
<body>
<div class="container-fluid" >
    <div class="row">
        <div class="col-lg-4">
            <div class="panel panel-primary">
                <div class="panel-heading">
                    <h3>
                        登录<br><br>
                        <small>欢迎登录后台管理系统</small>
                    </h3>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" id="login_form">
                        <div class="form-group">
                            <label for="pname" class="col-sm-2 control-label">账号</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="pname" name="pname" placeholder="请输入账号">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="pwd" class="col-sm-2 control-label">密码</label>
                            <div class="col-sm-10">
                                <input type="password" class="form-control" id="pwd" name="pwd" placeholder="请输入密码">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-lg-12" align="center">
                                <a class="btn btn-warning" href="javascript:login()">登录</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>